﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using GeneralDFS.BusinessLogical.Nodes;
using GeneralDFS.DataEntity.Nodes;
using GeneralDFS.DataEntity.Statistics;
using GeneralDFS.Interface.Nodes;

namespace GeneralDFS.BusinessLogical.Statistics
{
    /// <summary>
    /// NameNode统计分析
    /// </summary>
    [Serializable]
    public class NameNodeStatistics : MachineCounter
    {
        [NonSerialized]
        private readonly NameNode _nameNode;
        
        /// <summary>
        /// NameNode统计分析
        /// </summary>
        /// <param name="node"></param>
        /// <exception cref="Exception"></exception>
        public NameNodeStatistics(IBaseNode node)
        {
            if (node.GetType() == typeof (NameNode))
            {
                _nameNode = node as NameNode;
                return;
            }
            throw new Exception("this is not a NameNode");
        }

        public NameNodeInfo NameNodeInfo;
        public DateTime StatisticTime=DateTime.Now;

        /// <summary>
        /// DataNodeCenter中活动节点的数目
        /// </summary>
        public int DataNodeCount;

        /// <summary>
        /// DataNodeCenter中不可达节点的数目
        /// </summary>
        public int UnreachDataNodeCount;

        /// <summary>
        /// BlockMap中的Block数目
        /// </summary>
        public int BlockCount;

        public void Excute()
        {
            NameNodeInfo = _nameNode.LocalNode;
            DataNodeCount = _nameNode.DataNodeCenter.AliveNodeCount();
            UnreachDataNodeCount = _nameNode.DataNodeCenter.UnreachNodeCount();
            BlockCount = _nameNode.BlockManager.GetBlockMap().Count();
        }

        
    }
}
